<div class="bg-light lter b-b wrapper-md">
  <h1 class="m-n font-thin h3">EPG管理</h1>
</div>



<div class="wrapper-md"  >
<div class="panel panel-default">
  <div ng-controller="epgEditCtrl">
    <div class="row">
    
      <div class="col-sm-12" >
        <form name="form-contact" ng-submit="processForm()" class="form-horizontal">

            <div class="panel-heading">
              <span class="h4">

<button class="btn btn-default btn-sm " ng-click="goBack()"><i class="fa fa-mail-reply fa-lg"></i>&nbsp; 返回</button>


              </span>
            </div>
            <div class="panel-body">
            
              <p class="text-muted"><span class="label label-info">频道:{{channelName}}</span></p> 
     <div class="form-group">   
    <label  class="col-sm-1 control-label">节目名称</label>
    <div class="col-sm-5">
      <input type="text" class="form-control" placeholder="节目名称" ng-model="contact.ProgramName"  >
    </div>
  </div>
  <div class="line line-dashed b-b line-lg pull-in"></div>


  <div class="form-group">
     <label class="col-sm-1 control-label">节目简介</label>  
   <div class="col-sm-10">
       <textarea class="form-control" rows="6" ng-model="contact.ProgramIntroduction" placeholder="节目简介"></textarea>
   </div>
  </div>
 <div class="line line-dashed b-b line-lg pull-in"></div>
   
  <div class="form-group">
    <label class="col-sm-1 control-label">开始时间</label>
    <div class="col-sm-2">
 <input type="text"  ng-model="contact.BeginTime" id="BeginTime"   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="form-control" />
    </div>

  <label  class="col-sm-1 control-label">结束时间</label>
    <div class="col-sm-2">
 <input type="text"  ng-model="contact.EndTime" id="EndTime"   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="form-control" />
    </div>

  <div class="line line-dashed b-b line-lg pull-in"></div>

  <!--隐藏字段-->
<input type="hidden"  ng-model="contact.Id"  >
<input type="hidden"  ng-model="channelId"  >
<!-- <input type="hidden"  ng-model="contact.ChannelId"  > -->
<input type="hidden"  ng-model="contact.ProgramName"  >
<input type="hidden"  ng-model="contact.ProgramIntroduction"  >
<input type="hidden"  ng-model="contact.BeginTime"  >
<input type="hidden"  ng-model="contact.EndTime"  >
<input type="hidden"  ng-model="contact.AdderId"  >
<input type="hidden"  ng-model="contact.AdderName"  >
<input type="hidden"  ng-model="contact.AddTime"  >
<input type="hidden"  ng-model="contact.UpdaterId"  >
<input type="hidden"  ng-model="contact.UpdaterName"  >
<input type="hidden"  ng-model="contact.UpdateTime"  >
<input type="hidden"  ng-model="contact.DelFlag" ng-init="contact.DelFlag='0'" >

    <!--隐藏字段-->

            <footer class="panel-footer text-right bg-light lter">
              <button type="submit" class="btn btn-success">提交</button>
            </footer>
          </div>
        </form>
      </div>
    </div>
   
</div>
</div>




</div>

<!--angularjs-->
<script type="text/javascript">
  'use strict';
app.controller('epgEditCtrl', function ($scope, $state, $stateParams,$http,$window) {


//返回按钮：开始
$scope.$window = $window;
    $scope.goBack = function() {
      $window.history.back();
    };
//返回按钮：结束

var channelId = $stateParams.cId;
var infoId = $stateParams.epgId;
$scope.channelId = channelId;

//获取频道信息
  var getprogramUrl = API_URL+"channel_info?query=delflag:0,Id:"+channelId;

  var channel = MY_ASYNC_AJAX(getprogramUrl)[0];

  $scope.channelName = channel.ChannelName;
   

//如果infoId不为空，查询详情：开始
  if(''!=infoId){
      var getInfoUrl = API_URL+"channel_epg?query=delflag:0,id:"+infoId+"&sortby=updateTime&order=desc"; 
        $http.get(getInfoUrl).success(function (response) {
         var obj = response[0];
          obj.BeginTime = getDateTime(obj.BeginTime);
         obj.EndTime = getDateTime(obj.EndTime);
          obj.ChannelId = channelId;
        $scope.contact = obj;
      });
  }

  //表单提交开始
$scope.processForm= function (){


  //1.参数处理

//发起POST请求
var postInfoUrl = API_URL+"channel_epg";
var formData =  $scope.contact;


  //1.参数处理
     formData.BeginTime = forDbDateTime($('#BeginTime').val());
    formData.EndTime = forDbDateTime($('#EndTime').val());
    formData.AddTime = getNowDBFormatDate();
    formData.UpdateTime = getNowDBFormatDate();
    formData.AdderId = 1;
    formData.AdderName = 'admin';
    formData.UpdaterId = 1;
    formData.UpdaterName = 'admin';
    formData.ChannelId = Number(channelId);

console.log(JSON.stringify(formData));
console.log(formData.Id);
console.log(infoId);
    
  if("undefined"!=typeof(formData.Id)){

          $.ajax( {  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'put', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl+'/'+infoId, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                      console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 
                    
                  top.layer.msg('保存成功', {icon: 6});

                  //2.成功跳转页面
                   $window.history.go(-1);
                  }  
              }); 


         }else{

         $.ajax( {  
                  async : false, //是否异步  
                  cache : false, //是否使用缓存  
                  type : 'post', //请求方式,post  
                  dataType : "json", //数据传输格式  
                  url : postInfoUrl, //请求链接  
                  data: JSON.stringify(formData),
                  error : function() {  
                      console.log('亲，网络有点不给力呀！');  
                  },  
                  success : function(data) { 

                    top.layer.msg('保存成功', {icon: 6});
                 //2.成功跳转页面
                 $window.history.go(-1);
                  }  
             }); 

          }


 

  
}

 //表单提交结束

});
</script>
<!--angularjs-->










